import { _decorator, Component, instantiate, Node, ParticleSystem2D, Prefab, randomRangeInt } from 'cc';
import { Item } from './Item';
import { MigaManager } from './MigaManager';
import { PoolManager } from '../../Scripts/Framework/Managers/PoolManager';
const { ccclass, property } = _decorator;

@ccclass('Gift')
export class Gift extends Item {

    @property(Node)
    particle: Node;

    @property(Node)
    items: Node;

    OpenGift() {
        if (this.isMove) return;
        let num = randomRangeInt(0, this.items.children.length - 1);
        let item = instantiate(this.items.children[num]);
        item.setParent(MigaManager.Instance.touchPanel);
        item.setWorldPosition(this.node.getWorldPosition());
        item.active = true;
        let particle = instantiate(this.particle);
        particle.setParent(MigaManager.Instance.touchPanel);
        particle.setWorldPosition(this.node.getWorldPosition());
        particle.active = true;
        console.log(item.getWorldPosition(), this.node.getWorldPosition());
        PoolManager.PutNode(this.node);
    }
}


